/* jshint indent: 2 */
module.exports = (app) => {
  const sequelize = app.model;
  const DataTypes = app.Sequelize.DataTypes;
  const Article = sequelize.define('article', {
    id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
    },
    article: {
      type: DataTypes.STRING(255),
      comment: '说说的文字',
    },
    pictures: {
      type: DataTypes.STRING(1000),
      comment: '说说的图片',
    },
    tags: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: '说说的标签',
    },
    // creatorId: {
    //   field: 'creator_id',
    //   type: DataTypes.INTEGER(11),
    //   comment: '说说用户',
    // },
    status: {
      field: 'status',
      type: DataTypes.INTEGER(1),
      defaultValue: 0,
      comment: '状态，0:正常，1:封禁',
    },
  }, {
    createdAt: 'create_time', // 记录创建时间
    updatedAt: 'update_time', // 记录更新时间
    freezeTableName: true, // 不允许修改表名
  });

  Article.associate = () => {
    app.model.Article.belongsTo(app.model.User, {
      as: 'creator',
      foreignKey: 'creatorId',
    });
    app.model.Article.hasMany(app.model.Comment, {
      // as: 'article',
      foreignKey: 'articleId',
    });
  };
  return Article;
};
